<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>快照对比页面,情绪计算</title>
<style type="text/css">
table.gridtable {
	font-family: verdana, arial, sans-serif;
	font-size: 11px;
	color: #333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}

table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}

table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}

tr:hover td {
	background: none;
}

tr:hover {
	background-color: none;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  padding: 8px;
  text-align: left;
}

th {
  background-color: #f2f2f2;
}
#myDiv { 
     top: 0px;
     right: 0;
     background-color: #f1f1f1;
     padding: 10px;
     overflow-y:auto;
   }
</style>
<meta charset="UTF-8">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/grid1.0.js"></script>
</head>
<body style="overflow:auto;">

<button id="bt0">计算所有(当天)</button>
<button id="bt1">按涨跌幅排序</button>
<button id="bt2">按距离最小值排序</button>
<button id="bt3">按zhang5排序</button> 
<button id="bt6">按最近5天成交总和排序</button> 
<input type="text" style="width:50px;" id="zhang5text" placeholder="小于" value="10"> 
 <button id="bt4">隐藏zhang5</button>
 <input type="text" style="width:50px;" id="sumcj" placeholder="小于" value="10"> 
 <button id="bt5">隐藏成交量</button> 
  <input type="text" style="width:50px;" id="guanjianci" placeholder="小于" value="10"> 
 <button id="bt7">过滤关键字</button> 
 <button id="bt8">显示所有</button> 
  <button id="bt9">概念计算</button> 
 <select id="selectDate"></select>
<div id="myDiv0" style="line-height:20px;width:100%;height:30px;"></div>
<div id="myDiv"></div>
<script type="text/javascript">
(function(){ 
	
	var arr = [];
	$("#bt9").click(function(){
		var visibleRows = $('table tr:visible');
		// 遍历每一行并进行操作
		visibleRows.each(function() {
		    // 在这里对每一行执行所需的操作 
		    var tdValue = $(this).find('td[name="gn1"]').text(); 
		    var tdarr = tdValue.split(",");
		    arr = $.merge(arr, tdarr); 
		});
		 var wordCount = {};
		    arr.forEach(function(word) {
		        if (wordCount[word]) {
		            wordCount[word]++;
		        } else {
		            wordCount[word] = 1;
		        }
		    });
	
	    // Convert the dictionary to an array of key-value pairs and sort it by frequency
	    var sortedWordCount = Object.entries(wordCount).sort((a, b) => b[1] - a[1]);
	    
	    console.log(sortedWordCount); // 输出每行的文本内容 
	    for (var i = 0; i < sortedWordCount.length; i++) { 
	    	var arr1 = sortedWordCount[i]; 
	    	$("#myDiv0").append("<lable>"+arr1[0]+"("+arr1[1]+")"+"</lable>");
	    	if(i>=10){
	    		break;
	    	}
		}
	    
	    
		    
		
	});
	

	
	
	$("#bt4").click(function(){ 
		
		var value = $("#zhang5text").val();
		$('td[name=zhang5]').each(function() {
		    if(parseInt($(this).text()) < value) {
		        $(this).closest('tr').hide();
		    }
		});
	});
	
	function loadUrl(){
		$('table tr').each(function() {
		    var thirdColumn = $(this).find('td:eq(2)');
		    var linkText = thirdColumn.text();  
		    thirdColumn.html('<a href=http://quote.eastmoney.com/concept/'+linkText+'.html target="_blank">' + linkText + '</a>');
		 });
	}
	
	function load(createTime){
		//alert(createTime);
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getSunfa3",  
			dataType:'text',
			data:{createTime:createTime},
			success : function(msg) {  
				 $("#myDiv").html(msg);
				 $("#mytalbe").addClass("gridtable");  
				 chang2wei();
				 $('table td[name="table_id"]').hide();
				 $('table th[name="table_id"]').hide();
				 $('table td[name="price"]').hide();
				 $('table th[name="price"]').hide();
				 
				 $('table td[name="temp1"]').hide();
				 $('table th[name="temp1"]').hide();
				 
				 $('table td[name="temp2"]').hide();
				 $('table th[name="temp2"]').hide();
				 
				 $('table td[name="temp3"]').hide();
				 $('table th[name="temp3"]').hide();
				 loadUrl();
				 
				 $("table td:nth-child(9)").each(function() {
					    var value = parseFloat($(this).text());
					    if (value < 0) {
					        $(this).css("color", "green");
					    } else if (value >= 0) {
					        $(this).css("color", "red");
					    }
				});  
				 tableCooking();
				 $('table tr').each(function() {
				        var thirdTdValue = $(this).find('td:eq(1)').text();  
						   var allCode = getCookie('allCode');
						   var arr =allCode.split(",");
						   for(var i=0;i<arr.length;i++){ 
							   if(arr[i]==thirdTdValue){
								   $(this).children().css('background-color', 'gray')
								   break;
							   }
						   } 
				  }); 
			}
		}); 
	}
	
	load('');
	loaoDayCreateTime();  
	 
	
	function jusuanfenqi(flag){  
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getjisuan3",  
			data:{flag:flag},
			dataType:'text',
			success : function(msg) {  
			  alert("调用成功");
			}
		});
	}; 

	function loaoDayCreateTime(flag){  
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getSuanFa3select",  
			dataType:'json',
			success : function(msg) {  
			 // alert(msg); 
			 	 $.each(msg, function(index, value) {
				    $('#selectDate').append($('<option>', {
				      value: value,
				      text: value
				    }));
				  });
			 	 
			 	 $('#selectDate').change(function(){
					    var selectedValue = $(this).val(); 
					    $("#myDiv").html("");
					    //alert(selectedValue);
						load(selectedValue); 
				 });
				
			 	 
			}
		});
	
	}; 
	
 
	$("#bt1").click(function(){
		
		if(bt1t==true){
			bt1t=false;
			sortTable0(bt1t);
		}else{
			bt1t =true;
			sortTable0_1(bt1t);
		}  
		
	});
	$("#bt2").click(function(){
		
		if(bt1t==true){
			bt1t=false;
			sortTable1(bt1t);
		}else{
			bt1t =true;
			sortTable1_1(bt1t);
		}  
		
	});
	$("#bt3").click(function(){
		
		if(bt1t==true){
			bt1t=false;
			sortTable2(bt1t);
		}else{
			bt1t =true;
			sortTable2_1(bt1t);
		}  
		
	});
	$("#bt6").click(function(){
		
		if(bt1t==true){
			bt1t=false;
			sortTable6(bt1t);
		}else{
			bt1t =true;
			sortTable6_1(bt1t);
		}  
		
	});
	 
	function sortTable0(temp){  
		 
		$('table tbody tr').sort(function(a, b) {
	        return parseInt($('td[name=dqzhangdifu]', a).text()) - parseInt($('td[name=dqzhangdifu]', b).text());
	    }).appendTo('table tbody');
	}
	 
	function sortTable0_1(temp){  
		 
		$('table tbody tr').sort(function(a, b) {
	        return parseInt($('td[name=dqzhangdifu]', b).text()) - parseInt($('td[name=dqzhangdifu]', a).text());
	    }).appendTo('table tbody');
	}
	
	 
	function sortTable1(temp){  
		 
		$('table tbody tr').sort(function(a, b) {
	        return parseInt($('td[name=julizuixiao]', a).text()) - parseInt($('td[name=julizuixiao]', b).text());
	    }).appendTo('table tbody');
	}

	function sortTable1_1(temp){  
		 
		$('table tbody tr').sort(function(a, b) {
	        return parseInt($('td[name=julizuixiao]', b).text()) - parseInt($('td[name=julizuixiao]', a).text());
	    }).appendTo('table tbody');
	}
	
	function sortTable2(temp){   
		$('table tbody tr').sort(function(a, b) {
	        return parseInt($('td[name=zhang5]', b).text()) - parseInt($('td[name=zhang5]', a).text());
	    }).appendTo('table tbody');
	}
	function sortTable2_1(temp){   
		$('table tbody tr').sort(function(a, b) {
	        return parseInt($('td[name=zhang5]', a).text()) - parseInt($('td[name=zhang5]', b).text());
	    }).appendTo('table tbody');
	}
	function sortTable6(temp){   
		$('table tbody tr').sort(function(a, b) {
	        return parseInt($('td[name=sumcjl5]', b).text()) - parseInt($('td[name=sumcjl5]', a).text());
	    }).appendTo('table tbody');
	}
	function sortTable6_1(temp){   
		$('table tbody tr').sort(function(a, b) {
	        return parseInt($('td[name=sumcjl5]', a).text()) - parseInt($('td[name=sumcjl5]', b).text());
	    }).appendTo('table tbody');
	}
	
	function tableCooking(){
		$(document).on('dblclick', 'tr', function() {
			var allCode = getCookie('allCode');
			if(allCode.length>0){
				var text = $(this).find("td:eq(1)").text();
				   $(this).children().css('background-color', 'gray');
				var temp = allCode.indexOf(text);
				if(temp==-1){
					allCode+=","+text;
					setCookie('allCode', allCode,1000);
				}else{
					allCode = allCode.replace(text,"");
					setCookie('allCode', allCode,1000);
				}
				 
			}else{
				var text = $(this).find("td:eq(3)").text();
				allCode=text;
				setCookie('allCode', allCode,1000);
				return;
			} 
		});
	}
	
	
	var bt1t = true;
	
	$("#bt0").click(function(){
		jusuanfenqi(-1);
	});
 
	
	
	
 
	 
	
	$("#bt3").click(function(){
			 $('table tr').each(function() {
		        var cellValue = parseFloat($(this).find('td[name="zuorihuanshoulv"]').text());

		        // Check if the cell value is greater than 3 or less than -2.5
		        if (cellValue < $("#sumcj").val()) {
		            $(this).hide(); // Hide the current row if the condition is met
		        }
		    });
	}); 
	
	
	$("#bt4").click(function(){
			
			if(bt1t == true){
				bt1t =false;
			}else{
				bt1t = true;
			} 
			sortTable(4,bt1t);
	});
	
	$("#bt4_1").click(function(){
		
		if(bt1t == true){
			bt1t =false;
		}else{
			bt1t = true;
		} 
		sortTable(11,bt1t);
});
	
	
	$("#bt5").click(function(){
		 $('table tr').each(function() {
		        var cellValue = parseFloat($(this).find('td[name="zuorizhangdiefu"]').text());

		        // Check if the cell value is greater than 3 or less than -2.5
		       if (cellValue < $("#sumcj").val()) {
		            $(this).hide(); // Hide the current row if the condition is met
		        }
		    });
	}); 
	$("#bt7").click(function(){ 
		 var  value=$("#guanjianci").val();
		 $('table td[name=gn1]:not(:contains("'+value+'"))').closest('tr').not(':first-child').hide();
	});
	$("#bt8").click(function(){ 
		 $("table tr").show();
	});
	
	  
	
	function sortTable(columnIndex, ascending) {
	    // 选择包含数字的行，并按特定列中包含的数字排序
	    var rows = $('table tbody tr').get();
	    rows.sort(function(rowA, rowB) {
	        var numA = parseFloat($(rowA).find('td').eq(columnIndex).text());
	        var numB = parseFloat($(rowB).find('td').eq(columnIndex).text());

	        if (ascending) {
	            return numA - numB;
	        } else {
	            return numB - numA;
	        }
	    });

	    // 重新排列行
	    $.each(rows, function(index, row) {
	        $('table tbody').append(row);
	    });
	}
	function sortTable(columnIndex, ascending) {
	    // 选择包含数字的行，并按特定列中包含的数字排序
	    var rows = $('table tbody tr').get();
	    rows.sort(function(rowA, rowB) {
	        var numA = parseFloat($(rowA).find('td').eq(columnIndex).text());
	        var numB = parseFloat($(rowB).find('td').eq(columnIndex).text());

	        if (ascending) {
	            return numA - numB;
	        } else {
	            return numB - numA;
	        }
	    }); 
	    // 重新排列行
	    $.each(rows, function(index, row) {
	        $('table tbody').append(row);
	    });
	}
	
	
	
	function loadUrl(){
		$('table td[name=code1]').each(function() {
		    var linkText = $(this).text();  
		    if(linkText=="code"){
		    	return;
		    }
		    $(this).html('<a href="javascript:void(0);">' + linkText + '</a>').click(function(){  
		    	if(linkText.indexOf("6")==0){
		    		window.open('http://quote.eastmoney.com/concept/sh'+linkText+'.html'); 	
		    	}else{
		    		window.open('http://quote.eastmoney.com/concept/sz'+linkText+'.html'); 
		    	}
		    	   
	    		  
		    });;
		 });
	}
	
	function checkURLExists(url, callback) {
	    $.ajax({
	        type: 'HEAD',
	        url: url,
	        success: function() {
	            callback(true);
	        },
	        error: function() {
	            callback(false);
	        }
	    });
	}

	// Usage
	
	
	function chang2wei(){
		
		$('table td[name="zuorizhangdiefu"]').each(function() {
		    var cellValue = $(this).text();
		    
		    // 将单元格中的文本转换为浮点数，并格式化为两位小数
		    var floatValue = parseFloat(cellValue);
		    if (!isNaN(floatValue)) {
		        var formattedValue = floatValue.toFixed(2);
		        $(this).text(formattedValue);
		    }
		});
		
		$('table td[name="zuorihuanshoulv"]').each(function() {
		    var cellValue = $(this).text();
		    
		    // 将单元格中的文本转换为浮点数，并格式化为两位小数
		    var floatValue = parseFloat(cellValue);
		    if (!isNaN(floatValue)) {
		        var formattedValue = floatValue.toFixed(2);
		        $(this).text(formattedValue);
		    }
		});
		$('table td[name="dqhuanshoulv"]').each(function() {
		    var cellValue = $(this).text();
		    
		    // 将单元格中的文本转换为浮点数，并格式化为两位小数
		    var floatValue = parseFloat(cellValue);
		    if (!isNaN(floatValue)) {
		        var formattedValue = floatValue.toFixed(2);
		        $(this).text(formattedValue);
		    }
		});
		$('table td[name="chaju"]').each(function() {
		    var cellValue = $(this).text();
		    
		    // 将单元格中的文本转换为浮点数，并格式化为两位小数
		    var floatValue = parseFloat(cellValue);
		    if (!isNaN(floatValue)) {
		        var formattedValue = floatValue.toFixed(2);
		        $(this).text(formattedValue);
		    }
		}); 
	}
	function setCookie(cookieName, cookieValue, expirationDays) {
	    const date = new Date();
	    date.setTime(date.getTime() + (expirationDays * 24 * 60 * 60 * 1000));
	    const expires = "expires=" + date.toUTCString();
	    document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/";
	}
	function getCookie(cookieName) {
	    const name = cookieName + "=";
	    const decodedCookie = decodeURIComponent(document.cookie);
	    const cookieArray = decodedCookie.split(';');
	    
	    for (let i = 0; i < cookieArray.length; i++) {
	        let cookie = cookieArray[i].trim();
	        if (cookie.indexOf(name) === 0) {
	            return cookie.substring(name.length);
	        }
	    }
	    return "";
	}
	
})();
  
</script>

</body>
</html>